
package com.compuvest.web;

import java.util.Calendar;
import java.util.Date;

public class Coupon implements java.io.Serializable {

    private String code;
    private String prefix;
    private double price;
    private int validDays;
    private Calendar now;
    private Calendar working;

    public Coupon() {
	this(10.00, 30, "N");
    }

    public Coupon(double price, int days, String prefix) {
	this.price = price;
	this.validDays = days;
	this.prefix = prefix;

	code = Integer.toString((int)(Math.random() * 999999) + 1000000).substring(1,7); // 000000 - 999999
	now = Calendar.getInstance();
    }

    // couponPrefix + advertCoupon -> N670307
    public String getCode()	{ return prefix + code; }
    public double getPrice()	{ return price; }
    public int getDays()	{ return validDays; }

    public Date getValidDate() {
	working = (Calendar)now.clone();
	working.add(Calendar.DAY_OF_YEAR, validDays); // add month
	return working.getTime();
    }

}
